﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;

namespace YougeBookmark.Models
{
    /// <summary>
    /// 书签实体类
    /// 对应数据库Bookmarks表
    /// </summary>
    [Table("Bookmarks")]
    public class Bookmark
    {
        [Key]
        [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        public int Id { get; set; }

        [Required(ErrorMessage = "URL不能为空")]
        [Column(TypeName = "TEXT")]
        public string Url { get; set; }

        [Required(ErrorMessage = "标题不能为空")]
        [Column(TypeName = "TEXT")]
        [MaxLength(500)]
        public string Title { get; set; }

        [Column(TypeName = "TEXT")]
        public string Summary { get; set; }

        [Column(TypeName = "TEXT")]
        public string ThumbnailPath { get; set; }

        [Column(TypeName = "TEXT")]
        public string Remark { get; set; }

        [Required]
        [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        public DateTime CreatedAt { get; set; }

        // 导航属性 - 与标签的关联关系
        public virtual ICollection<BookmarkTag> BookmarkTags { get; set; } = new List<BookmarkTag>();

        /// <summary>
        /// 获取关联标签的快捷方式（不映射到数据库）
        /// </summary>
        [NotMapped]
        public IEnumerable<Tag> Tags => BookmarkTags?.Select(bt => bt.Tag) ?? Enumerable.Empty<Tag>();
    }
}